package com.cmw.core.kit.email;

import java.util.ResourceBundle;

import com.cmw.core.kit.file.FileUtil;
import com.cmw.core.util.StringHandler;

public abstract class EmailAdapter implements EmailInter {
	
	static final String EMAIL_CONFIG_FILE = "email.properties";
	protected static ResourceBundle resourceObj = null;
	//SMTP 服务器
	protected static String smtpHost = null;
	//SMTP 端口 
	protected static int smtpPort = 465;
	//SMTP SSL 加密 [true:加密,false：不加密]
	protected static boolean ssl = false;
	//Email邮箱 
	protected static String formEmail = null;
	//Email 邮号
	protected static String account = null;
	/**
	 * Email 密码
	 */
	protected static String pwd = null;
	static{
		try {
			resourceObj = FileUtil.getResourceObj(EMAIL_CONFIG_FILE);
			smtpHost = resourceObj.getString("mail.smtp.host");
			String smtpPortStr = resourceObj.getString("mail.smtp.port");
			if(StringHandler.isValidStr(smtpPortStr)) smtpPort = Integer.parseInt(smtpPortStr);
			String sslStr = resourceObj.getString("mail.smtp.ssl");
			if(StringHandler.isValidStr(sslStr)) ssl = Boolean.parseBoolean(sslStr);
			formEmail = resourceObj.getString("mail.account");
			if(StringHandler.isValidStr(formEmail)){
				account = formEmail.split("@")[0];
			}
			pwd = resourceObj.getString("mail.pwd");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
